package top.lileix.example.netty.chat;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import top.lileix.example.netty.chat.AndroidClient.Notification;

public class ChatClientHandler extends SimpleChannelInboundHandler<String> {
	Notification notification;

	public ChatClientHandler(Notification notification) {
		this.notification = notification;
	}

	public ChatClientHandler() {

	}

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
		System.err.println("服务器响应：" + msg);
		if (null != notification) {
			notification.notif(msg);
		}
	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
		cause.printStackTrace();
		ctx.close();
	}
}
